package com.embrace.controller;

import com.embrace.entity.Student;
import com.embrace.service.StudentService;
import com.embrace.utils.res.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@AllArgsConstructor
@RestController
@RequestMapping("/student")
public class StudentController {

    private final StudentService studentService;

    @GetMapping("/getStudentById")
    public R getStudentById(Integer id) {
        Student student = studentService.getStudentById(id);
        if (null != student) {
            return R.data(student);
        }
        return R.fail("未查询到相关信息！");
    }


    @PostMapping("/insertStudent")
    public R insertStudent(@RequestBody Student student) {
        return R.status(studentService.insertStudent(student.getId(), student.getName(), student.getAge(), student.getGender(), student.getMajor()));
    }

    @PostMapping("/updateStudentById")
    public R updateStudentById(Integer id) {
        return R.status(studentService.updateStudentById(id));
    }


    @PostMapping("/deleteStudentById")
    public R deleteStudentById(Integer id) {
        return R.status(studentService.deleteStudentById(id));
    }
}
